home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / editbt / employee.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-05-08  |  11.7 KB  |  396 lines

  1. VERSION 2.00
  2. Begin Form frmEmployees 
  3.    BackColor       =   &H00FFFFFF&
  4.    Caption         =   "Employee Records"
  5.    ClientHeight    =   3495
  6.    ClientLeft      =   1830
  7.    ClientTop       =   1620
  8.    ClientWidth     =   5775
  9.    Height          =   3900
  10.    Left            =   1770
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   3495
  13.    ScaleWidth      =   5775
  14.    Top             =   1275
  15.    Width           =   5895
  16.    Begin ComboBox cbPosition 
  17.       BackColor       =   &H00C0C0C0&
  18.       Height          =   300
  19.       Left            =   2400
  20.       TabIndex        =   7
  21.       Text            =   " "
  22.       Top             =   1675
  23.       Width           =   3105
  24.    End
  25.    Begin MaskEdBox tbSSN 
  26.       BackColor       =   &H00C0C0C0&
  27.       DataField       =   "SSN"
  28.       DataSource      =   "Data1"
  29.       Format          =   "###-##-####"
  30.       Height          =   285
  31.       Left            =   2400
  32.       MousePointer    =   3  'I-Beam
  33.       PromptChar      =   "_"
  34.       PromptInclude   =   0   'False
  35.       TabIndex        =   5
  36.       Top             =   1175
  37.       Width           =   1400
  38.    End
  39.    Begin CheckBox Check1 
  40.       Alignment       =   1  'Right Justify
  41.       Caption         =   "&Active:"
  42.       DataField       =   "Active"
  43.       DataSource      =   "Data1"
  44.       Height          =   225
  45.       Left            =   1350
  46.       TabIndex        =   8
  47.       Top             =   2115
  48.       Width           =   1260
  49.    End
  50.    Begin TextBox tbLName 
  51.       BackColor       =   &H00C0C0C0&
  52.       DataField       =   "Last Name"
  53.       DataSource      =   "Data1"
  54.       Height          =   285
  55.       Left            =   2415
  56.       MaxLength       =   15
  57.       MousePointer    =   3  'I-Beam
  58.       TabIndex        =   3
  59.       Text            =   " "
  60.       Top             =   675
  61.       Width           =   1875
  62.    End
  63.    Begin TextBox tbFName 
  64.       BackColor       =   &H00C0C0C0&
  65.       DataField       =   "First Name"
  66.       DataSource      =   "Data1"
  67.       Height          =   285
  68.       Left            =   2400
  69.       MaxLength       =   15
  70.       MousePointer    =   3  'I-Beam
  71.       TabIndex        =   1
  72.       Text            =   " "
  73.       Top             =   175
  74.       Width           =   1875
  75.    End
  76.    Begin PictureBox picCommand 
  77.       Height          =   525
  78.       Index           =   0
  79.       Left            =   0
  80.       ScaleHeight     =   495
  81.       ScaleWidth      =   5775
  82.       TabIndex        =   9
  83.       Top             =   2700
  84.       Width           =   5800
  85.       Begin CommandButton Command1 
  86.          Caption         =   "E&xit Program"
  87.          Height          =   330
  88.          Left            =   3000
  89.          TabIndex        =   11
  90.          Top             =   75
  91.          Width           =   1400
  92.       End
  93.       Begin CommandButton cmdedit 
  94.          Caption         =   "&Edit"
  95.          Height          =   330
  96.          Left            =   1400
  97.          TabIndex        =   10
  98.          Top             =   75
  99.          Width           =   1400
  100.       End
  101.    End
  102.    Begin Data Data1 
  103.       BackColor       =   &H00C0C0C0&
  104.       Caption         =   "Employees"
  105.       Connect         =   ""
  106.       DatabaseName    =   "C:\VB\EMPLOYEE.MDB"
  107.       Exclusive       =   0   'False
  108.       Height          =   300
  109.       Left            =   0
  110.       Options         =   0
  111.       ReadOnly        =   0   'False
  112.       RecordSource    =   "Employees"
  113.       Top             =   3220
  114.       Width           =   5800
  115.    End
  116.    Begin PictureBox picCommand 
  117.       Height          =   525
  118.       Index           =   1
  119.       Left            =   0
  120.       ScaleHeight     =   495
  121.       ScaleWidth      =   5775
  122.       TabIndex        =   13
  123.       Top             =   2700
  124.       Visible         =   0   'False
  125.       Width           =   5800
  126.       Begin CommandButton cmdSave 
  127.          Caption         =   "&Save"
  128.          Default         =   -1  'True
  129.          Height          =   330
  130.          Left            =   1400
  131.          TabIndex        =   12
  132.          Top             =   75
  133.          Width           =   1400
  134.       End
  135.       Begin CommandButton cmdCancel 
  136.          Cancel          =   -1  'True
  137.          Caption         =   "&Cancel"
  138.          Height          =   330
  139.          Left            =   3000
  140.          TabIndex        =   14
  141.          Top             =   75
  142.          Width           =   1400
  143.       End
  144.    End
  145.    Begin Label lblFields 
  146.       Alignment       =   1  'Right Justify
  147.       BackStyle       =   0  'Transparent
  148.       Caption         =   "&Position:"
  149.       Height          =   210
  150.       Index           =   3
  151.       Left            =   195
  152.       TabIndex        =   6
  153.       Top             =   1700
  154.       Width           =   1800
  155.    End
  156.    Begin Label lblFields 
  157.       Alignment       =   1  'Right Justify
  158.       BackStyle       =   0  'Transparent
  159.       Caption         =   "&Soc. Sec. No.:"
  160.       Height          =   210
  161.       Index           =   2
  162.       Left            =   195
  163.       TabIndex        =   4
  164.       Top             =   1200
  165.       Width           =   1800
  166.    End
  167.    Begin Label lblFields 
  168.       Alignment       =   1  'Right Justify
  169.       BackStyle       =   0  'Transparent
  170.       Caption         =   "&Last Name:"
  171.       Height          =   210
  172.       Index           =   1
  173.       Left            =   195
  174.       TabIndex        =   2
  175.       Top             =   700
  176.       Width           =   1800
  177.    End
  178.    Begin Label lblFields 
  179.       Alignment       =   1  'Right Justify
  180.       BackStyle       =   0  'Transparent
  181.       Caption         =   "&First Name:"
  182.       Height          =   210
  183.       Index           =   0
  184.       Left            =   195
  185.       TabIndex        =   0
  186.       Top             =   200
  187.       Width           =   1800
  188.    End
  189.   '-----------------------------------------------------
  190.   '     Copyright (c) 1994 by Barth Riley
  191.   ' Project Name:       Edit Data Demonstration
  192.   ' Description:        Implements Edit button and
  193.   '                     read-only controls with a
  194.   '                     Data Control
  195.   ' Author:             Barth Riley
  196.   ' Copyright date:     Jan 29th, 1994
  197.   ' Version:            1.0
  198.   ' Project file:       EDITDATA.MAK
  199.   ' Number of forms:    1
  200.   ' Number of modules:  1
  201.   '-------------------------------------------------
  202.   '---Dim Variables
  203.   Dim fEdit As Integer    ' Edit mode flag
  204.   Dim fLoading As Integer ' True when a new rec. is loaded
  205. Sub cbPosition_DropDown ()
  206.   If Not fEdit Then
  207.     ' Temporarily disable the control
  208.     Beep
  209.     cbPosition.SelLength = 0
  210.     cbPosition.Enabled = False
  211.     cbPosition.Enabled = True
  212.   End If
  213. End Sub
  214. Sub cbPosition_GotFocus ()
  215.   If fEdit Then
  216.     cbPosition.SelStart = 0
  217.     cbPosition.SelLength = Len(cbPosition.Text)
  218.   End If
  219. End Sub
  220. Sub cbPosition_KeyDown (KeyCode As Integer, Shift As Integer)
  221.   If Not fEdit Then
  222.     Beep
  223.     KeyCode = 0
  224.   End If
  225. End Sub
  226. Sub cbPosition_KeyPress (KeyAscii As Integer)
  227.   If Not fEdit Then
  228.     Beep
  229.     KeyAscii = 0
  230.   End If
  231. End Sub
  232. Sub cbPosition_LostFocus ()
  233.   cbPosition.SelLength = 0
  234. End Sub
  235. Sub Check1_Click ()
  236.   If fEdit Or fLoading Then
  237.   Else
  238.     '-----------------------------------------------
  239.     ' The Data control will intialize
  240.     ' the values of all bound controls
  241.     ' prior to the Form_Load event.  Hence
  242.     ' both fEdit and fLoading will be False
  243.     ' when the Check1 control is initialized.
  244.     ' It will "appear" therefore that the user
  245.     ' is trying to alter the value of the ckeck box
  246.     ' when not in edit mode.  To overcome this problem,
  247.     ' I've used theTag property of the control to
  248.     ' indicate whether the control has been
  249.     ' initialized:  If it has no value, then it
  250.     ' is set to "Loading".  Otherwise, a warning
  251.     ' beep is sounded.
  252.     '---------------------------------------------------
  253.     If Check1.Tag = "" Then
  254.       Check1.Tag = "Loaded"
  255.     Else
  256.       Beep
  257.     End If
  258.     Check1.Value = (Data1.Recordset("Active") * -1)
  259.   End If
  260. End Sub
  261. Sub cmdCancel_Click ()
  262.   Data1.UpdateControls    ' Abandon changes to the rec.
  263.   EnableCtls False        ' Back to read-only mode
  264. End Sub
  265. Sub cmdEdit_Click ()
  266.   EnableCtls True   ' Allow edits
  267. End Sub
  268. Sub cmdSave_Click ()
  269.   tbSSN.PromptInclude = True
  270.   ' Update unbound controls
  271.   Data1.Recordset("Position") = cbPosition.ListIndex + 1
  272.   Data1.Recordset.Update
  273.   EnableCtls False    ' Back to read-only mode
  274. End Sub
  275. Sub Command1_Click ()
  276.   Data1.Recordset.Close
  277.   End
  278. End Sub
  279. Sub Data1_Reposition ()
  280.   tbSSN.Mask = tbSSN.Text     ' Set Mask to field value
  281.   ' Set unbound controls
  282.   cbPosition.ListIndex = Data1.Recordset("Position") - 1
  283.   fLoading = False
  284. End Sub
  285. Sub Data1_Validate (Action As Integer, Save As Integer)
  286.   If Action >= 1 And Action <= 4 Then
  287.     ' User moving to a new record
  288.     If fEdit Then
  289.       ' We want to prevent the user from moving to
  290.       ' a new record when s/he is editing the
  291.       ' current record.
  292.       Action = 0 ' Cancel move operation
  293.       Save = 0
  294.     Else
  295.       fLoading = True ' allow controls to be updated
  296.       tbSSN.Mask = "###-##-####"
  297.     End If
  298.   End If
  299. End Sub
  300. Sub EnableCtls (ByVal fEditOn As Integer)
  301.   ' Set the text box controls to the appropriate
  302.   ' edit mode
  303.   fEdit = fEditOn
  304.   SetTBReadOnly tbFName, Not fEditOn
  305.   SetTBReadOnly tbLName, Not fEditOn
  306.   If fEditOn Then
  307.     ' Reset the Mask and text properties for tbSSN
  308.     tbSSN.PromptInclude = False
  309.     szMask = tbSSN.Mask
  310.     tbSSN.Mask = ""
  311.     tbSSN.Mask = "###-##-####"
  312.     Data1.Caption = "Employee Records [Edit Mode]"
  313.     tbFName.SetFocus
  314.   Else
  315.     tbSSN.Mask = ""
  316.     tbSSN.Mask = tbSSN.Text
  317.     tbSSN.PromptInclude = True
  318.     Data1.Caption = "Employee Records [Read-Only]"
  319.   End If
  320.   ' Set the TabStop values...
  321.   tbFName.TabStop = fEditOn
  322.   tbLName.TabStop = fEditOn
  323.   tbSSN.TabStop = fEditOn
  324.   cbPosition.TabStop = fEditOn
  325.   Check1.TabStop = fEditOn
  326.   ' Make the appropriate command button group visible
  327.   picCommand(0).Visible = Not fEditOn
  328.   picCommand(1).Visible = fEditOn
  329.   ' Set the default and cancel properties for
  330.   ' each set of command buttons
  331.   cmdEdit.Default = Not fEditOn
  332.   cmdSave.Default = fEditOn
  333.   cmdCancel.Cancel = fEditOn
  334.   If fEdit Then Data1.Recordset.Edit
  335.   '---End of code
  336. End Sub
  337. Sub Form_Load ()
  338.   fLoading = True
  339.   cbPosition.AddItem "Accountant"
  340.   cbPosition.AddItem "Consultant"
  341.   cbPosition.AddItem "Documentation Proofreader"
  342.   cbPosition.AddItem "Head Honcho"
  343.   cbPosition.AddItem "Project Manager"
  344.   cbPosition.AddItem "Programmer"
  345.   cbPosition.AddItem "Systems Analyst"
  346.   cbPosition.AddItem "Technical Writer"
  347.   Data1.Caption = "Employee List [Read-only]"
  348.   EnableCtls False
  349.   fLoading = False
  350. End Sub
  351. Sub tbFName_GotFocus ()
  352.   If fEdit Then
  353.     tbFName.SelStart = 0
  354.     tbFName.SelLength = Len(tbFName.Text)
  355.   End If
  356. End Sub
  357. Sub tbFName_KeyDown (KeyCode As Integer, Shift As Integer)
  358.   If Not fEdit Then Beep
  359. End Sub
  360. Sub tbFName_KeyPress (KeyAscii As Integer)
  361.   If Not fEdit Then Beep
  362. End Sub
  363. Sub tbFName_LostFocus ()
  364.   tbFName.SelLength = 0
  365. End Sub
  366. Sub tbLName_GotFocus ()
  367.   If fEdit Then
  368.     tbLName.SelStart = 0
  369.     tbLName.SelLength = Len(tbLName.Text)
  370.   End If
  371. End Sub
  372. Sub tbLName_KeyDown (KeyCode As Integer, Shift As Integer)
  373.   If Not fEdit Then Beep
  374. End Sub
  375. Sub tbLName_KeyPress (KeyAscii As Integer)
  376.   If Not fEdit Then Beep
  377. End Sub
  378. Sub tbLName_LostFocus ()
  379.   tbLName.SelLength = 0
  380. End Sub
  381. Sub tbSSN_GotFocus ()
  382.   If fEdit Then
  383.     tbSSN.SelStart = 0
  384.     tbSSN.SelLength = 11
  385.   End If
  386. End Sub
  387. Sub tbSSN_KeyDown (KeyCode As Integer, Shift As Integer)
  388.   If Not fEdit Then Beep
  389. End Sub
  390. Sub tbSSN_KeyPress (KeyAscii As Integer)
  391.   If Not fEdit Then Beep
  392. End Sub
  393. Sub tbSSN_LostFocus ()
  394.   tbSSN.SelLength = 0
  395. End Sub
  396.